﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MulagoDb.database;
using MulagoDb.model;
using System.Collections;
using MulagoDb.model_old.clinicvisit.tab2;
//using MulagoDb.model_old;
//using MulagoDb.model_old.clinicvisit.tab2;


namespace MulagoDb
{
    public partial class ClinicVisitPanel : UserControl
    {
        private IList<Clinicvisit> patientVisits;
       // private IList<object> patientVisitDetails;
        private bool isInUpdateMode = false;
        public string date;

        public ClinicVisitPanel()
        {
            InitializeComponent();
            updateBtn.Enabled = false;
            updateBtn1.Enabled = false;
            updateBtn3.Enabled = false;
        }

        private void tabControl_indexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Name.Equals("tabPage2"))
            {
                if (isInUpdateMode) {
                    IList<ClinicvisitDaycare> daycares = PatientReg.biodata.clinicvisitDaycares;
                    if (daycares.Count <= 0) {
                        cdcare = new ClinicvisitDaycare();
                    }
                    foreach (ClinicvisitDaycare cd in daycares) {
                        if (DateTime.Compare(cd.date, DateTime.Parse(date)) == 0)
                        {
                            cdcare = cd;
                            fillDaycareGeneral(cdcare);
                            break;
                        }
                        else {
                            cdcare = new ClinicvisitDaycare();
                        }
                    }
                    IList<ClinicvisitRbctranfusation> crbc = PatientReg.biodata.clinicvisitRbctranfusations;
                    if (crbc.Count <= 0) {
                        rbc = new ClinicvisitRbctranfusation();
                        rbc2 = new ClinicvisitRbctranfusation();
                        rbc3  = new ClinicvisitRbctranfusation();
                    }else{
                        for (int i = 0; i < crbc.Count; ++i)
                        {
                            ClinicvisitRbctranfusation cr = (ClinicvisitRbctranfusation)crbc.ElementAt(i);
                            if (cr.date.Equals(date))
                            {
                                fillRbctranfusion(cr, i+1);
                            }
                            else {
                                //this is not the best way to do this!!!!
                                rbc = new ClinicvisitRbctranfusation();
                                rbc2 = new ClinicvisitRbctranfusation();
                                rbc3 = new ClinicvisitRbctranfusation();
                            }
                        }
                    }
                }
            }
            else if (tabControl1.SelectedTab.Name.Equals("tabPage3"))
            {
                if (isInUpdateMode) {
                    IList<ClinicvisitDeposition> disposition = PatientReg.biodata.clinicvisitDepositions;
                    if (disposition.Count <= 0)
                    {
                        cvdp = new ClinicvisitDeposition();
                    }
                    else {
                        fillDisposition(disposition);
                    }
                }
            }
        }
        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void treeView5_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        private void ClinicVisitPanel_Load(object sender, EventArgs e)
        {
            grid1.BorderStyle = BorderStyle.FixedSingle;
            grid1.ColumnsCount = 3;
            grid1.FixedRows = 1;
            grid1.Rows.Insert(0);
            grid1[0, 0] = new SourceGrid.Cells.ColumnHeader("");
            grid1[0, 0].Column.Width = 300;
            grid1[0, 1] = new SourceGrid.Cells.ColumnHeader("Simple transfusion ");
            grid1[0, 1].Column.Width = 200;
            grid1[0, 2] = new SourceGrid.Cells.ColumnHeader("Manual exchange transfusion ");
            grid1[0, 2].Column.Width = 200;

            grid1.Rows.Insert(1);
            grid1[1, 0] = new SourceGrid.Cells.Cell("Whole blood #units", typeof(string));
            grid1[1, 1] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[1, 2] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[1, 0].Row.Height = 50;

            grid1.Rows.Insert(2);
            grid1[2, 0] = new SourceGrid.Cells.Cell("Paediatric packed cells  #units", typeof(string));
            grid1[2, 1] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[2, 2] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[2, 0].Row.Height = 50;

            grid1.Rows.Insert(3);
            grid1[3, 0] = new SourceGrid.Cells.Cell("Adult  packed cells   #units", typeof(string));
            grid1[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[3, 2] = new SourceGrid.Cells.Cell("", typeof(string));
            grid1[3, 0].Row.Height = 50;

            grid1.Width = grid1.Parent.Width;
            patientnameLbl.Text = patientnameLbl.Text + " " + FindPatient.patienceName;
            pateintL.Text = pateintL.Text + " " + FindPatient.patienceName;
            patientLbl3.Text = patientLbl3.Text + " " + FindPatient.patienceName;

            patientVisits = PatientReg.biodata.clinicvisits;
            if (patientVisits.Count <= 0)
            {
                MessageBox.Show(this, "No Clinic Visit Details for: " + FindPatient.patienceName);
            }
            else
            {
                foreach (Clinicvisit pv in patientVisits)
                {
                    string patientDetails = pv.patient.pid + "  " + pv.date + "  " + pv.reason;
                    patientVisitListBox.Items.Add(patientDetails);

                }
            }


        }

        private void grid1_Paint(object sender, PaintEventArgs e)
        {


        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void tabPage3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string response = "Successfully submitted";
            Clinicvisit visit = new Clinicvisit();
            visit.patient = PatientReg.biodata;
            visit.reason = reasonForvisitCombo.Text;
            visit.date = datePicker.Text;
            string res = ClinicVisit.insertClinicvisit(visit);
            //string res = ClinicVisit.insertClinicvisit(FindPatient.patientId, datePicker.Text, reasonForvisitCombo.Text);
            if (res.Contains("Duplicate entry"))
            {
                response = "Could not submit data,You can only have one clinic visit in a day";
            }
            else
            {
                ClinicvisitVitalsigns vs = new ClinicvisitVitalsigns();
                vs.bp = bpTfld.Text;
                vs.date = DateTime.Parse(datePicker.Text);
                vs.hr = hrTfld.Text;
                vs.rr = rrTfld.Text;
                vs.temperature = temperatureTfld.Text;
                vs.o2sat = o2satTfld.Text;
                vs.patient = PatientReg.biodata;
                ClinicVisit.insertClinicvisit_vitalsigns(vs);
                //===========================
                ClinicvisitMeasurements cm = new ClinicvisitMeasurements();
                cm.patient = PatientReg.biodata;
                cm.date = DateTime.Parse(datePicker.Text);
                cm.height = htTfld.Text;
                cm.weight = wtTfld.Text;
                cm.leftmuac =  leftMuacTfld.Text;
                ClinicVisit.insertClinicvisit_measurements(cm);
                //============================

                ClinicvisitPhysicalexamination cp = new ClinicvisitPhysicalexamination();
                cp.patient = PatientReg.biodata;
                cp.date = DateTime.Parse(datePicker.Text);
                cp.history = historyTfld.Text;
                cp.pallor = pallorCombo.Text;
                cp.juandice = juandiceCombo.Text;
                cp.liver =  liverCombo.Text;
                cp.spleen = spleenCombo.Text;
                cp.other = otherTarea.Text;
                ClinicVisit.insertClinicvisit_physicalexamination(cp);
                //================================

                ClinicvisitInvestigations ci = new ClinicvisitInvestigations();
                ci.patient = PatientReg.biodata;
                ci.date = DateTime.Parse(datePicker.Text);
                ci.hb = hbTfld.Text;
                ci.mcv = mcvTfld.Text;
                ci.wbc = wbcTfld.Text;
                ci.neutrophils = neutrophilisTfld.Text;
                ci.platelets = platelatesTfld.Text;
                ci.malaria = malariaCombo.Text;
                ci.reticulocytes = reticulocytesTfld.Text;
                ci.bilirubinDirect = bilirubinDirectTld.Text;
                ci.bilirubinTotal = bilirubinTfld.Text;
                cp.other = otherTarea.Text;
                ClinicVisit.insertClinicvisit_investigations(ci);

                ClinicvisitMajordiagnosis cmajor = new ClinicvisitMajordiagnosis();
                cmajor.patient = PatientReg.biodata;
                cmajor.date = DateTime.Parse(datePicker.Text);
                cmajor.stablestate = stablestateChkBox.Checked ? "T" : "F";
                cmajor.splenicSquesation = spleenCombo.Text;
                cmajor.cholecystitisHeadache = CholecystitischeckBox.Checked ? "T" : "F";
                cmajor.acutesyndrome = AcutechestsyndromecheckBox.Checked ? "T" : "F";
                ClinicVisit.insertClinicvisit_majordiagnosis(cmajor);

                //tree view data
                ArrayList febrileValues = getTreeNodeState(FebrileIllinessTree);
                ClinicvisitFebrileillness cf = new ClinicvisitFebrileillness();
                cf.patient = PatientReg.biodata;
                cf.date = DateTime.Parse(datePicker.Text);
                cf.probableMalaria = Convert.ToChar(febrileValues[0].ToString());
                cf.tbSuspected =  Convert.ToChar(febrileValues[1].ToString());
                cf.otherRespiratory = Convert.ToChar(febrileValues[2].ToString());
                cf.gastroenteritis = Convert.ToChar(febrileValues[3].ToString());
                cf.osteomyelitis = Convert.ToChar(febrileValues[4].ToString());
                cf.probableSepsis = Convert.ToChar(febrileValues[6].ToString());
                cf.noSpecificFocus = Convert.ToChar(febrileValues[5].ToString());
                cf.otherSpecify = Convert.ToChar(febrileValues[7].ToString());
                ClinicVisit.insertclinicvisit_febrileillness(cf);

                ClinicvisitDactylitis cd = new ClinicvisitDactylitis();
                ArrayList dactylitis = getTreeNodeState(dactylitisTree);
                cd.patient =  PatientReg.biodata;
                cd.date = DateTime.Parse(datePicker.Text);
                cd.rhand  =  Convert.ToChar(dactylitis[0].ToString());
                cd.lhand =   Convert.ToChar(dactylitis[1].ToString());
                cd.rfoot =   Convert.ToChar(dactylitis[2].ToString());
                cd.lfoot = Convert.ToChar(dactylitis[3].ToString());
                ClinicVisit.insertclinicvisit_dactylitis(cd);

                //
                ArrayList stroke = getTreeNodeState(strokeTree);
                ClinicvisitStroke cs = new ClinicvisitStroke();
                cs.patient =PatientReg.biodata;
                cs.date = DateTime.Parse(datePicker.Text);
                cs.rupperLimb=Convert.ToChar(stroke[0].ToString());
                cs.rlowerLimb =Convert.ToChar(stroke[1].ToString());
                cs.lupperLimb=Convert.ToChar(stroke[2].ToString());
                cs.llowerLimb =Convert.ToChar(stroke[3].ToString());
                cs.dysphasia =Convert.ToChar(stroke[4].ToString());
                cs.cranialnerve =Convert.ToChar(stroke[5].ToString());
                cs.other =Convert.ToChar(stroke[6].ToString());                
                ClinicVisit.insertclinicvisit_stroke(cs);

                
                //
                ArrayList acutePain = getTreeNodeState(acutePainTree);
                ClinicvisitAcutepain cva = new ClinicvisitAcutepain();                
                cva.patient=PatientReg.biodata;
                cva.date = DateTime.Parse(datePicker.Text);
                cva.thorax = Convert.ToChar(acutePain[0].ToString());
                cva.abdomen =Convert.ToChar(acutePain[1].ToString());
                cva.back= Convert.ToChar(acutePain[2].ToString());
                cva.hips =Convert.ToChar(acutePain[3].ToString());
                cva.lupperLimb=Convert.ToChar(acutePain[4].ToString());
                cva.llowerLimb=Convert.ToChar(acutePain[5].ToString());
                cva.rupperLimb=Convert.ToChar(acutePain[6].ToString());
                cva.rlowerLimb = Convert.ToChar(acutePain[7].ToString());
                ClinicVisit.insertclinicvisit_acutepain(cva);


                //
                ArrayList avascularnecrosis = getTreeNodeState(avascularNecrosisTree);
                ClinicvisitAvascularnecrosis cava = new ClinicvisitAvascularnecrosis();
                cava.patient = PatientReg.biodata;
                cava.date = DateTime.Parse(datePicker.Text);
                cava.rhumerus = Convert.ToChar(avascularnecrosis[0].ToString());
                cava.lhumerus = Convert.ToChar(avascularnecrosis[1].ToString());
                cava.rfemarolhead =Convert.ToChar(avascularnecrosis[2].ToString());
                cava.lfemoralhead=Convert.ToChar(avascularnecrosis[3].ToString());
                cava.other= Convert.ToChar(avascularnecrosis[4].ToString());
                ClinicVisit.insertclinicvisit_avascularnecrosis(cava);
            }
            MessageBox.Show(this,response);
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void textBox19_TextChanged(object sender, EventArgs e)
        {

        }

        private void FebrileIllinesscheckBox_CheckedChanged(object sender, EventArgs e)
        {

        }

        public ArrayList getTreeNodeState(TreeView tree)
        {
            ArrayList nodeStates = new ArrayList();
            foreach (TreeNode pnode in tree.Nodes)
            {
                foreach (TreeNode cnode in pnode.Nodes)
                {
                    if (cnode.Checked)
                    {
                        nodeStates.Add("T");
                    }
                    else
                    {
                        nodeStates.Add("F");
                    }
                }
            }
            return nodeStates;
        }
        public ArrayList getPatientDeposition()
        {
            ArrayList nodestates = new ArrayList();
            string folicacid = "";
            string mutivitamin = "";
            string malariaprophylaxis = "";
            string pneumococcal = "";
            string analgesics = "";
            string antibiotics = "";
            string antihelminth = "";
            string antimalarials = "";
            string others = "";
            foreach (TreeNode tnode in patientDepositionTreeview.Nodes)
            {
                foreach (TreeNode cnode in tnode.Nodes)
                {
                    //go deep in each node to get child states
                    if (cnode.Text.Equals("Folic acid"))
                    {
                        folicacid = cnode.Checked ? "T" : "F";
                    }
                    else if (cnode.Text.Trim().Equals("Mutivitamin".Trim()))
                    {
                        mutivitamin = cnode.Checked ? "T" : "F";
                    }
                    else if (cnode.Text.Trim().Equals("Malaria prophylaxis".Trim()))
                    {
                        malariaprophylaxis = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Pneumococcal prophylaxis".Trim()))
                    {
                        pneumococcal = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Analgesics".Trim()))
                    {
                        analgesics = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Antibiotics (other than other prophylaxis)".Trim()))
                    {
                        antibiotics = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Anti-helminth".Trim()))
                    {
                        antihelminth = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Anti-malarials (other than prophylaxis)".Trim()))
                    {
                        antimalarials = getState(cnode).ToString();
                    }
                    else if (cnode.Text.Trim().Equals("Anti-malarials (other than prophylaxis)".Trim()))
                    {
                        others = cnode.Checked ? "T" : "F";
                    }

                }
            }
            nodestates.Add(folicacid);
            nodestates.Add(mutivitamin);
            nodestates.Add(malariaprophylaxis);
            nodestates.Add(pneumococcal);
            nodestates.Add(analgesics);
            nodestates.Add(antibiotics);
            nodestates.Add(antihelminth);
            nodestates.Add(antimalarials);
            nodestates.Add(others);
            return nodestates;
        }
        public StringBuilder getState(TreeNode parent)
        {
            StringBuilder nodestates = new StringBuilder();
            foreach (TreeNode tnode in parent.Nodes)
            {
                nodestates.Append(tnode.Checked ? "T," : "F,");
            }
            return nodestates;
        }
        public void setState(String states,TreeNode parent) {
            string[] state = states.Split(',');
            int ctr = 0;
            parent.Checked = true;
            foreach (TreeNode tnode in parent.Nodes) {
                if(state[ctr].Equals("T")&& ctr < state.Length){
                    tnode.Checked = true;
                    parent.Checked = true;
                }
                ctr += 1;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            ClinicvisitDaycare cdcare = new ClinicvisitDaycare();            
            cdcare.patient = PatientReg.biodata;
            cdcare.date = DateTime.Parse(datePicker.Text);
            cdcare.nodaycaregiven =Convert.ToChar(nodaycareCheckbox.Checked ? "T" : "F") ;
            cdcare.ivfluids = ivfluidsCheck.Checked ? "T" : "F";
            cdcare.analgesia =analgesiaCheck.Checked?analgesiaCombo.Text:"" ;
            cdcare.antibiotics =antibioticsCheck.Checked?antibioticsCombo.Text:"" ;
            cdcare.other = otherTextArea.Text;
            ClinicVisit.insertclinicvisit_daycare(cdcare);
            //add grid values
            ClinicvisitRbctranfusation rbc = new ClinicvisitRbctranfusation();            
            rbc.patient = PatientReg.biodata;
            rbc.date =  (new DateTime()).ToString();
            rbc.type = grid1[1, 0].DisplayText;
            rbc.sampletransition =grid1[1, 1].DisplayText ;
            rbc.manualexchange = grid1[1, 2].DisplayText;

            ClinicvisitRbctranfusation rbc2 = new ClinicvisitRbctranfusation();            
            rbc2.patient = PatientReg.biodata;
            rbc2.date = (new DateTime()).ToString();
            rbc2.type = grid1[2, 0].DisplayText;
            rbc2.sampletransition =grid1[2, 1].DisplayText ;
            rbc2.manualexchange = grid1[2, 2].DisplayText;

            
            ClinicvisitRbctranfusation rbc3 = new ClinicvisitRbctranfusation();            
            rbc3.patient = PatientReg.biodata;
            rbc3.date = (new DateTime()).ToString();
            rbc3.type = grid1[3, 0].DisplayText;
            rbc3.sampletransition =grid1[3, 1].DisplayText ;
            rbc3.manualexchange = grid1[3, 2].DisplayText;

            ClinicVisit.insertClinicvisit_rbctranfusation(rbc);
            ClinicVisit.insertClinicvisit_rbctranfusation(rbc2);
            ClinicVisit.insertClinicvisit_rbctranfusation(rbc3);
            MessageBox.Show(this, "Successfully added");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ArrayList result = getPatientDeposition();
            ClinicvisitDeposition cvdp = new ClinicvisitDeposition();
            cvdp.patient = PatientReg.biodata;
            cvdp.disposition =  patientDispoCombo.Text;
            cvdp.date = DateTime.Parse(datePicker.Text);
            cvdp.folicacid =  result[0].ToString();
            cvdp.mutivitamin =  result[1].ToString();
            cvdp.malariaprophylaxis = result[2].ToString();
            cvdp.pneumococcal = result[3].ToString();
            cvdp.analgesics = result[4].ToString();
            cvdp.antibiotics = result[5].ToString();
            cvdp.antihelminth = result[6].ToString();
            cvdp.antimalarials = result[7].ToString();
            cvdp.other = result[8].ToString();
            ClinicVisit.insertclinicvisit_deposition(cvdp);

            MessageBox.Show(this, "Successfully submitted");
        }

        private void patientnameLbl_Click(object sender, EventArgs e)
        {

        }

        private void patientVisitListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = patientVisitListBox.SelectedIndex;
            resetFields();
            if (index >= 0)
            {
                Patient p = PatientReg.biodata;
                string patientId =Convert.ToString(((Clinicvisit)patientVisits[index]).patient.pid);
                date = ((Clinicvisit)patientVisits[index]).date;
                visit = (Clinicvisit)patientVisits[index];
                reasonForvisitCombo.Text = visit.reason;
                fillVitalSigns(p.clinicvisitVitalsignses);

                fillMeasurements(p.clinicvisitMeasurementses);

                fillphysicalexamination(p.clinicvisitPhysicalexaminations);

                fillinvestigations(p.clinicvisitInvestigationses);

                fillmajordiagnosis(p.clinicvisitMajordiagnosises);

                fillfebrileillness(p.clinicvisitFebrileillnesses);

                fillacutepain(p.clinicvisitAcutepains);

                fillavascularnecrosis(p.clinicvisitAvascularnecrosises);

                fillstroke(p.clinicvisitStrokes);

                filldactylitis(p.clinicvisitDactylitises);

                isInUpdateMode = true;
                //should enable all update buttons here, 
                updateBtn.Enabled = true;
                submitBtn.Enabled= false;
                submitBtn2.Enabled= false;
                updateBtn1.Enabled = true;
                updateBtn3.Enabled = true;
                submitBtn3.Enabled = false;
            }
            else { 
            }

        }
        public void clearTreeView(TreeView tree)
        {
            foreach (TreeNode cnode in tree.Nodes)
            {
                if (cnode.Checked)
                {
                    cnode.Checked = false;
                }
                foreach (TreeNode ccnode in cnode.Nodes)
                {
                    if (ccnode.Checked)
                    {
                        ccnode.Checked = false;
                    }
                    foreach (TreeNode cccnode in ccnode.Nodes)
                    {
                        if (cccnode.Checked)
                        {
                            cccnode.Checked = false;
                        }
                    }
                }
            }
        }

        public void fillVitalSigns(IList<ClinicvisitVitalsigns> patientVisitDetails)
        {
            if (patientVisitDetails.Count <= 0)
            {
                clinicVisitVitalSigns = new ClinicvisitVitalsigns();
            }
            else
            {
                foreach (ClinicvisitVitalsigns pv in patientVisitDetails)
                {
                    clinicVisitVitalSigns = pv;
                    hrTfld.Text = pv.hr;
                    rrTfld.Text = pv.rr;
                    bpTfld.Text = pv.bp;
                    temperatureTfld.Text = pv.temperature;
                    o2satTfld.Text = pv.o2sat;

                }
            }

        }

        public void fillMeasurements(IList<ClinicvisitMeasurements> patientVisitDetails)
        {
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitMeasurements = new ClinicvisitMeasurements(); 
            }
            else
            {
                foreach (ClinicvisitMeasurements pv in patientVisitDetails)
                {
                    clinicvisitMeasurements = pv;
                    htTfld.Text = pv.height;
                    wtTfld.Text = pv.weight;
                    leftMuacTfld.Text = pv.leftmuac;
                }
            }

        }

        public void fillphysicalexamination(IList<ClinicvisitPhysicalexamination> patientVisitDetails)
        {
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitphysicalexamination = new ClinicvisitPhysicalexamination();
            }
            else
            {
                foreach (ClinicvisitPhysicalexamination pv in patientVisitDetails)
                {
                    clinicvisitphysicalexamination = pv;
                    historyTfld.Text = pv.history;
                    pallorCombo.Text = pv.pallor;
                    juandiceCombo.Text = pv.juandice;
                    liverCombo.Text = pv.liver;
                    spleenCombo.Text = pv.spleen;
                    otherTfld.Text = pv.other;

                }
            }

        }

        public void fillinvestigations(IList<ClinicvisitInvestigations> patientVisitDetails)
        {
            if (patientVisitDetails.Count <= 0)
            {
                clinicVisitInvestigations = new ClinicvisitInvestigations();
            }
            else
            {
                foreach (ClinicvisitInvestigations pv in patientVisitDetails)
                {
                    clinicVisitInvestigations = pv;
                    hbTfld.Text = pv.hb;
                    mcvTfld.Text = pv.mcv;
                    wbcTfld.Text = pv.wbc;
                    neutrophilisTfld.Text = pv.neutrophils;
                    platelatesTfld.Text = pv.platelets;
                    malariaCombo.Text = pv.malaria;
                    reticulocytesTfld.Text = pv.reticulocytes;
                    bilirubinDirectTld.Text = pv.bilirubinDirect;
                    bilirubinTfld.Text = pv.bilirubinTotal;
                    otherTextArea.Text = pv.other;


                }
            }

        }

        public void fillmajordiagnosis(IList<ClinicvisitMajordiagnosis> patientVisitDetails)
        {
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitMajorDiagnosis = new ClinicvisitMajordiagnosis();
            }
            else
            {
                foreach (ClinicvisitMajordiagnosis pv in patientVisitDetails)
                {
                    clinicvisitMajorDiagnosis = pv;

                    if (pv.stablestate.Equals("T"))
                    {
                        stablestateChkBox.Checked = true;
                    }
                    if (pv.cholecystitisHeadache.Equals("T"))
                    {
                        CholecystitischeckBox.Checked = true;
                    }
                    if (pv.acutesyndrome.Equals("T"))
                    {
                        headacecheckBox1.Checked = true;
                    }
                    splenicCombo.Text = pv.splenicSquesation;

                }
            }

        }

        public void fillDaycareGeneral(ClinicvisitDaycare daycareGeneral) {
            if (daycareGeneral != null)
            {
                if (daycareGeneral.nodaycaregiven.ToString().Equals("T"))
                {
                    nodaycareCheckbox.Checked = true;
                }
                if (daycareGeneral.ivfluids.ToString().Equals("T"))
                {
                    ivfluidsCheck.Checked = true;
                }
                if (!daycareGeneral.analgesia.ToString().Equals(""))
                {
                    analgesiaCombo.Text = daycareGeneral.analgesia;
                    analgesiaCheck.Checked = true;
                }
                if (!daycareGeneral.antibiotics.ToString().Equals(""))
                {
                    antibioticsCombo.Text = daycareGeneral.antibiotics.ToString();
                    antibioticsCheck.Checked = true;
                }
                otherTextArea.Text = daycareGeneral.other.ToString();
            }
        }
        public void fillRbctranfusion(ClinicvisitRbctranfusation rbctransfusion,int row) {
            if (row == 1) {
                rbc = rbctransfusion;
            }
            if (row == 2) {
                rbc2 = rbctransfusion;
            }
            if (row == 3) {
                rbc3 = rbctransfusion;
            }
            grid1[row, 0].Value = rbctransfusion.type;
            grid1[row, 1].Value = rbctransfusion.sampletransition;
            grid1[row, 2].Value = rbctransfusion.manualexchange;
        }
        private void groupBox6_Enter(object sender, EventArgs e)
        {

        }
        
        private void updateBtn_Click(object sender, EventArgs e)
        {
            cdcare.patient = PatientReg.biodata;
            cdcare.date = DateTime.Parse(datePicker.Text);
            cdcare.nodaycaregiven = Convert.ToChar(nodaycareCheckbox.Checked ? "T" : "F");
            cdcare.ivfluids = ivfluidsCheck.Checked ? "T" : "F";
            cdcare.analgesia = analgesiaCheck.Checked ? analgesiaCombo.Text : "";
            cdcare.antibiotics = antibioticsCheck.Checked ? antibioticsCombo.Text : "";
            cdcare.other = otherTextArea.Text;
            ClinicVisit.insertclinicvisit_daycare(cdcare);
            //add grid values
            rbc.patient = PatientReg.biodata;
            rbc.date = datePicker.Text;
            rbc.type = grid1[1, 0].DisplayText;
            rbc.sampletransition = grid1[1, 1].DisplayText;
            rbc.manualexchange = grid1[1, 2].DisplayText;

            rbc2.patient = PatientReg.biodata;
            rbc2.date = datePicker.Text;
            rbc2.type = grid1[2, 0].DisplayText;
            rbc2.sampletransition = grid1[2, 1].DisplayText;
            rbc2.manualexchange = grid1[2, 2].DisplayText;


            rbc3.patient = PatientReg.biodata;
            rbc3.date = datePicker.Text;
            rbc3.type = grid1[3, 0].DisplayText;
            rbc3.sampletransition = grid1[3, 1].DisplayText;
            rbc3.manualexchange = grid1[3, 2].DisplayText;

            ClinicVisit.insertClinicvisit_rbctranfusation(rbc);
            ClinicVisit.insertClinicvisit_rbctranfusation(rbc2);
            ClinicVisit.insertClinicvisit_rbctranfusation(rbc3);
            MessageBox.Show(this, "Successfully Updated");
        }
        public void fillfebrileillness(IList<ClinicvisitFebrileillness> patientVisitDetails)
        {
            clearTreeView(FebrileIllinessTree);
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitFebrileIllness = new ClinicvisitFebrileillness();
            }
            else
            {
                foreach (ClinicvisitFebrileillness pv in patientVisitDetails)
                {
                    clinicvisitFebrileIllness = pv;
                    if (pv.probableMalaria == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Malaria/probable Malaria"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.osteomyelitis == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Osteomyelitis"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.noSpecificFocus == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("No specific Focus"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.gastroenteritis == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Gastroenteritis"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.otherRespiratory == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Other Respiratory"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.tbSuspected == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("TB/Suspected/Probable/Cofirmed"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.probableSepsis == 'T')
                    {
                        foreach (TreeNode pnode in FebrileIllinessTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Malaria/probable Malaria"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                }
            }

        }

        public void fillacutepain(IList<ClinicvisitAcutepain> patientVisitDetails)
        {
            clearTreeView(acutePainTree);
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitAcutePain = new ClinicvisitAcutepain();
            }
            else
            {
                foreach (ClinicvisitAcutepain pv in patientVisitDetails)
                {
                    clinicvisitAcutePain = pv;
                    if (pv.thorax == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Thorax"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.abdomen == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Abdomen"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.back == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Back"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.hips == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Hips"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lupperLimb == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Upper Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.llowerLimb == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Lower Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.rupperLimb == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Upper Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.rlowerLimb == 'T')
                    {
                        foreach (TreeNode pnode in acutePainTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Lower Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                }
            }

        }

        public void fillavascularnecrosis(IList<ClinicvisitAvascularnecrosis> patientVisitDetails)
        {
            clearTreeView(avascularNecrosisTree);
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitAvascularnecrosis = new ClinicvisitAvascularnecrosis();
            }
            else
            {
                foreach (ClinicvisitAvascularnecrosis pv in patientVisitDetails)
                {
                    clinicvisitAvascularnecrosis = pv;
                    if (pv.rhumerus == 'T')
                    {
                        foreach (TreeNode pnode in avascularNecrosisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Humerus"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lhumerus == 'T')
                    {
                        foreach (TreeNode pnode in avascularNecrosisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L humerus"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.rfemarolhead == 'T')
                    {
                        foreach (TreeNode pnode in avascularNecrosisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R femarol head"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lfemoralhead == 'T')
                    {
                        foreach (TreeNode pnode in avascularNecrosisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L femoral head"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }

                }
            }

        }

        public void fillstroke(IList<ClinicvisitStroke> patientVisitDetails)
        {
            clearTreeView(strokeTree);
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitStroke = new ClinicvisitStroke();
            }
            else
            {
                foreach (ClinicvisitStroke pv in patientVisitDetails)
                {
                    clinicvisitStroke = pv;
                    if (pv.rupperLimb == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Upper Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.rlowerLimb == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Lower Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lupperLimb == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Upper Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.llowerLimb == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Lower Limb"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.dysphasia == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("Dysphasia"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.cranialnerve == 'T')
                    {
                        foreach (TreeNode pnode in strokeTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("cranial nerve"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }

                }
            }

        }

        public void filldactylitis(IList<ClinicvisitDactylitis> patientVisitDetails)
        {
            clearTreeView(dactylitisTree);
            if (patientVisitDetails.Count <= 0)
            {
                clinicvisitDactylitis = new ClinicvisitDactylitis();
            }
            else
            {
                foreach (ClinicvisitDactylitis pv in patientVisitDetails)
                {
                    clinicvisitDactylitis = pv;
                    if (pv.rhand == 'T')
                    {
                        foreach (TreeNode pnode in dactylitisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Hand"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lhand == 'T')
                    {
                        foreach (TreeNode pnode in dactylitisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Hand"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.rfoot == 'T')
                    {
                        foreach (TreeNode pnode in dactylitisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("R Foot"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }
                    if (pv.lfoot == 'T')
                    {
                        foreach (TreeNode pnode in dactylitisTree.Nodes)
                        {
                            foreach (TreeNode cnode in pnode.Nodes)
                            {
                                if (cnode.Text.Equals("L Foot"))
                                {
                                    cnode.Checked = true;

                                }
                            }

                        }
                    }

                }
            }

        }
        
        public void fillDisposition(IList<ClinicvisitDeposition> disposition ) {
            clearTreeView(patientDepositionTreeview);
            if (disposition.Count <= 0)
            {
                cvdp = new ClinicvisitDeposition();
            }
            else {
                foreach (ClinicvisitDeposition cd in disposition) {
                    cvdp = cd;
                   // if (cd.folicacid.Equals("T")) {
                        foreach (TreeNode pnode in patientDepositionTreeview.Nodes) {
                            foreach (TreeNode cnode in pnode.Nodes) {
                                //go deep in each node to get child states
                                if (cnode.Text.Equals("Folic acid")&& cd.folicacid.Equals("T"))
                                {
                                    cnode.Checked = true;
                                }
                                else if (cnode.Text.Trim().Equals("Mutivitamin".Trim()) && cd.mutivitamin.Equals("T"))
                                {
                                    cnode.Checked = true;
                                }
                                else if (cnode.Text.Trim().Equals("Malaria prophylaxis".Trim()))
                                {
                                    setState(cd.malariaprophylaxis, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Pneumococcal prophylaxis".Trim()))
                                {
                                    setState(cd.pneumococcal, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Analgesics".Trim()))
                                {
                                    setState(cd.analgesics, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Antibiotics (other than other prophylaxis)".Trim()))
                                {
                                    setState(cd.antibiotics, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Anti-helminth".Trim()))
                                {
                                    setState(cd.antihelminth, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Anti-malarials (other than prophylaxis)".Trim()))
                                {
                                    setState(cd.antimalarials, cnode);
                                }
                                else if (cnode.Text.Trim().Equals("Other specify".Trim()) && cd.other.Equals("T"))
                                {
                                    cnode.Checked = true;
                                }

                            }
                        }
                   // }
                }
            }
        }

        public void resetFields()
        {
            reasonForvisitCombo.Text = "";
            hrTfld.Text = "";
            rrTfld.Text = "";
            bpTfld.Text = "";
            temperatureTfld.Text = "";
            o2satTfld.Text = "";
            stablestateChkBox.Checked = false;
            splenicSequestioncheckBox.Checked = false;
            splenicCombo.Text = "";
            headacecheckBox1.Checked = false;
            CholecystitischeckBox.Checked = false;
            clearTreeView(FebrileIllinessTree);
            clearTreeView(dactylitisTree);
            clearTreeView(strokeTree);
            htTfld.Text = "";
            wtTfld.Text = "";
            leftMuacTfld.Text = "";
            historyTfld.Text = "";
            AcutechestsyndromecheckBox.Checked = false;
            clearTreeView(acutePainTree);
            clearTreeView(avascularNecrosisTree);
            pallorCombo.Text = "";
            juandiceCombo.Text = "";
            liverCombo.Text = "";
            spleenCombo.Text = "";
            otherTarea.Text = "";
            hbTfld.Text = "";
            mcvTfld.Text = "";
            wbcTfld.Text = "";
            neutrophilisTfld.Text = "";
            platelatesTfld.Text = "";
            malariaCombo.Text = "";
            reticulocytesTfld.Text = "";
            bilirubinDirectTld.Text = "";
            bilirubinTfld.Text = "";
            otherTarea.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            resetFields();
        }
       private Clinicvisit visit;
       private ClinicvisitMeasurements clinicvisitMeasurements;
       private ClinicvisitPhysicalexamination clinicvisitphysicalexamination;
       private ClinicvisitVitalsigns clinicVisitVitalSigns;
       private ClinicvisitInvestigations clinicVisitInvestigations;
       private ClinicvisitMajordiagnosis clinicvisitMajorDiagnosis;
       private ClinicvisitFebrileillness clinicvisitFebrileIllness;
       private ClinicvisitDactylitis clinicvisitDactylitis;
       private ClinicvisitStroke clinicvisitStroke;
       private ClinicvisitAcutepain clinicvisitAcutePain;
       private ClinicvisitAvascularnecrosis clinicvisitAvascularnecrosis;
       private ClinicvisitDaycare cdcare;
       private ClinicvisitRbctranfusation rbc;
       private ClinicvisitRbctranfusation rbc2;
       private ClinicvisitRbctranfusation rbc3;
       private ClinicvisitDeposition cvdp;
        private void updateBtn1_Click(object sender, EventArgs e)
        {
            string response = "Successfully Updated";
            visit.patient = PatientReg.biodata;
            visit.reason = reasonForvisitCombo.Text;
            visit.date = datePicker.Text;
            string res = ClinicVisit.insertClinicvisit(visit);
            //string res = ClinicVisit.insertClinicvisit(FindPatient.patientId, datePicker.Text, reasonForvisitCombo.Text);
            if (res.Contains("Duplicate entry"))
            {
                response = "Could not submit data,You can only have one clinic visit in a day";
            }
            else
            {
                clinicVisitVitalSigns.bp = bpTfld.Text;
                clinicVisitVitalSigns.date = DateTime.Parse(datePicker.Text);
                clinicVisitVitalSigns.hr = hrTfld.Text;
                clinicVisitVitalSigns.rr = rrTfld.Text;
                clinicVisitVitalSigns.temperature = temperatureTfld.Text;
                clinicVisitVitalSigns.o2sat = o2satTfld.Text;
                clinicVisitVitalSigns.patient = PatientReg.biodata;
                ClinicVisit.insertClinicvisit_vitalsigns(clinicVisitVitalSigns);
                //===========================
                clinicvisitMeasurements.patient = PatientReg.biodata;
                clinicvisitMeasurements.date = DateTime.Parse(datePicker.Text);
                clinicvisitMeasurements.height = htTfld.Text;
                clinicvisitMeasurements.weight = wtTfld.Text;
                clinicvisitMeasurements.leftmuac = leftMuacTfld.Text;
                ClinicVisit.insertClinicvisit_measurements(clinicvisitMeasurements);
                //============================

                clinicvisitphysicalexamination.patient = PatientReg.biodata;
                clinicvisitphysicalexamination.date = DateTime.Parse(datePicker.Text);
                clinicvisitphysicalexamination.history = historyTfld.Text;
                clinicvisitphysicalexamination.pallor = pallorCombo.Text;
                clinicvisitphysicalexamination.juandice = juandiceCombo.Text;
                clinicvisitphysicalexamination.liver = liverCombo.Text;
                clinicvisitphysicalexamination.spleen = spleenCombo.Text;
                clinicvisitphysicalexamination.other = otherTarea.Text;
                ClinicVisit.insertClinicvisit_physicalexamination(clinicvisitphysicalexamination);
                //================================

                clinicVisitInvestigations.patient = PatientReg.biodata;
                clinicVisitInvestigations.date = DateTime.Parse(datePicker.Text);
                clinicVisitInvestigations.hb = hbTfld.Text;
                clinicVisitInvestigations.mcv = mcvTfld.Text;
                clinicVisitInvestigations.wbc = wbcTfld.Text;
                clinicVisitInvestigations.neutrophils = neutrophilisTfld.Text;
                clinicVisitInvestigations.platelets = platelatesTfld.Text;
                clinicVisitInvestigations.malaria = malariaCombo.Text;
                clinicVisitInvestigations.reticulocytes = reticulocytesTfld.Text;
                clinicVisitInvestigations.bilirubinDirect = bilirubinDirectTld.Text;
                clinicVisitInvestigations.bilirubinTotal = bilirubinTfld.Text;
                clinicVisitInvestigations.other = otherTarea.Text;
                ClinicVisit.insertClinicvisit_investigations(clinicVisitInvestigations);

                clinicvisitMajorDiagnosis.patient = PatientReg.biodata;
                clinicvisitMajorDiagnosis.date = DateTime.Parse(datePicker.Text);
                clinicvisitMajorDiagnosis.stablestate = stablestateChkBox.Checked ? "T" : "F";
                clinicvisitMajorDiagnosis.splenicSquesation = spleenCombo.Text;
                clinicvisitMajorDiagnosis.cholecystitisHeadache = CholecystitischeckBox.Checked ? "T" : "F";
                clinicvisitMajorDiagnosis.acutesyndrome = AcutechestsyndromecheckBox.Checked ? "T" : "F";
                ClinicVisit.insertClinicvisit_majordiagnosis(clinicvisitMajorDiagnosis);

                //tree view data
                ArrayList febrileValues = getTreeNodeState(FebrileIllinessTree);
                clinicvisitFebrileIllness.patient = PatientReg.biodata;
                clinicvisitFebrileIllness.date = DateTime.Parse(datePicker.Text);
                clinicvisitFebrileIllness.probableMalaria = Convert.ToChar(febrileValues[0].ToString());
                clinicvisitFebrileIllness.tbSuspected = Convert.ToChar(febrileValues[1].ToString());
                clinicvisitFebrileIllness.otherRespiratory = Convert.ToChar(febrileValues[2].ToString());
                clinicvisitFebrileIllness.gastroenteritis = Convert.ToChar(febrileValues[3].ToString());
                clinicvisitFebrileIllness.osteomyelitis = Convert.ToChar(febrileValues[4].ToString());
                clinicvisitFebrileIllness.probableSepsis = Convert.ToChar(febrileValues[6].ToString());
                clinicvisitFebrileIllness.noSpecificFocus = Convert.ToChar(febrileValues[5].ToString());
                clinicvisitFebrileIllness.otherSpecify = Convert.ToChar(febrileValues[7].ToString());
                ClinicVisit.insertclinicvisit_febrileillness(clinicvisitFebrileIllness);

                ArrayList dactylitis = getTreeNodeState(dactylitisTree);
                clinicvisitDactylitis.patient = PatientReg.biodata;
                clinicvisitDactylitis.date = DateTime.Parse(datePicker.Text);
                clinicvisitDactylitis.rhand = Convert.ToChar(dactylitis[0].ToString());
                clinicvisitDactylitis.lhand = Convert.ToChar(dactylitis[1].ToString());
                clinicvisitDactylitis.rfoot = Convert.ToChar(dactylitis[2].ToString());
                clinicvisitDactylitis.lfoot = Convert.ToChar(dactylitis[3].ToString());
                ClinicVisit.insertclinicvisit_dactylitis(clinicvisitDactylitis);

                //
                ArrayList stroke = getTreeNodeState(strokeTree);
                clinicvisitStroke.patient = PatientReg.biodata;
                clinicvisitStroke.date = DateTime.Parse(datePicker.Text);
                clinicvisitStroke.rupperLimb = Convert.ToChar(stroke[0].ToString());
                clinicvisitStroke.rlowerLimb = Convert.ToChar(stroke[1].ToString());
                clinicvisitStroke.lupperLimb = Convert.ToChar(stroke[2].ToString());
                clinicvisitStroke.llowerLimb = Convert.ToChar(stroke[3].ToString());
                clinicvisitStroke.dysphasia = Convert.ToChar(stroke[4].ToString());
                clinicvisitStroke.cranialnerve = Convert.ToChar(stroke[5].ToString());
                clinicvisitStroke.other = Convert.ToChar(stroke[6].ToString());
                ClinicVisit.insertclinicvisit_stroke(clinicvisitStroke);


                //
                ArrayList acutePain = getTreeNodeState(acutePainTree);
                clinicvisitAcutePain.patient = PatientReg.biodata;
                clinicvisitAcutePain.date = DateTime.Parse(datePicker.Text);
                clinicvisitAcutePain.thorax = Convert.ToChar(acutePain[0].ToString());
                clinicvisitAcutePain.abdomen = Convert.ToChar(acutePain[1].ToString());
                clinicvisitAcutePain.back = Convert.ToChar(acutePain[2].ToString());
                clinicvisitAcutePain.hips = Convert.ToChar(acutePain[3].ToString());
                clinicvisitAcutePain.lupperLimb = Convert.ToChar(acutePain[4].ToString());
                clinicvisitAcutePain.llowerLimb = Convert.ToChar(acutePain[5].ToString());
                clinicvisitAcutePain.rupperLimb = Convert.ToChar(acutePain[6].ToString());
                clinicvisitAcutePain.rlowerLimb = Convert.ToChar(acutePain[7].ToString());
                ClinicVisit.insertclinicvisit_acutepain(clinicvisitAcutePain);


                //
                ArrayList avascularnecrosis = getTreeNodeState(avascularNecrosisTree);
                clinicvisitAvascularnecrosis.patient = PatientReg.biodata;
                clinicvisitAvascularnecrosis.date = DateTime.Parse(datePicker.Text);
                clinicvisitAvascularnecrosis.rhumerus = Convert.ToChar(avascularnecrosis[0].ToString());
                clinicvisitAvascularnecrosis.lhumerus = Convert.ToChar(avascularnecrosis[1].ToString());
                clinicvisitAvascularnecrosis.rfemarolhead = Convert.ToChar(avascularnecrosis[2].ToString());
                clinicvisitAvascularnecrosis.lfemoralhead = Convert.ToChar(avascularnecrosis[3].ToString());
                clinicvisitAvascularnecrosis.other = Convert.ToChar(avascularnecrosis[4].ToString());
                ClinicVisit.insertclinicvisit_avascularnecrosis(clinicvisitAvascularnecrosis);
            }
            MessageBox.Show(this, response);
        }

        private void updateBtn3_Click(object sender, EventArgs e)
        {

            ArrayList result = getPatientDeposition();            
            cvdp.patient = PatientReg.biodata;
            cvdp.disposition = patientDispoCombo.Text;
            cvdp.date = DateTime.Parse(datePicker.Text);
            cvdp.folicacid = result[0].ToString();
            cvdp.mutivitamin = result[1].ToString();
            cvdp.malariaprophylaxis = result[2].ToString();
            cvdp.pneumococcal = result[3].ToString();
            cvdp.analgesics = result[4].ToString();
            cvdp.antibiotics = result[5].ToString();
            cvdp.antihelminth = result[6].ToString();
            cvdp.antimalarials = result[7].ToString();
            cvdp.other = result[8].ToString();
            ClinicVisit.insertclinicvisit_deposition(cvdp);

            MessageBox.Show(this, "Successfully Updated");
        }

    }
}
